import { useCallback } from "react";
import { useDispatch, useSelector } from "react-redux";
import Creator from "../store/actions";
// 引入api
import TypesApi from "../api/types";

export const useOneType = () => {
    // 获取对应父类型数据
    const oneType = useSelector(state => {
        return state.findType
    })
    const dispatch = useDispatch();
    // 操作状态的行为
    // 获取_id对应的父类型
    const findType = useCallback(async (_id) => {
        const data = await TypesApi.getOne({_id})
        dispatch(Creator.findType(data));
    }, [dispatch]);

    return [oneType, { findType }]

}